namespace SB2.Application
{
    /// <summary>
    /// 动态图表
    /// </summary>
    [ApiDescriptionSettings("Dynamic")]
    public class DynamicChartAppService : IAppAuthorizedService
    {
        DynamicChartRepository repository;
        public DynamicChartAppService(DynamicChartRepository repository)
        {
            this.repository = repository;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public async Task<DynamicChart> Add()
        {
            return await repository.GetNewAsync();
        }
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<DynamicChartDto> Get(long id)
        {
            var data = await repository.GetByIdAsync(id);
            return data.Adapt<DynamicChartDto>();
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<bool> Update(DynamicChart dto)
        {
            return await repository.Context.Updateable(dto).UpdateColumns(m => new { m.Content }).ExecuteCommandHasChangeAsync();
        }
        /// <summary>
        /// 修改基本信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<bool> UpdateInfo(DynamicChart dto)
        {
            return await repository.Context.Updateable(dto).UpdateColumns(m => new { m.name }).ExecuteCommandHasChangeAsync();
        }
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagedResponse<DynamicChartDto>> PageList(PageModel dto)
        {
            // Console.WriteLine(Furion.JsonSerialization.JSON.Serialize(dto));
            var list = await repository.GetPageListAsync(m => 1 == 1, dto, m => m.CreateTime, OrderByType.Desc);
            return new PagedResponse<DynamicChartDto>(list.Adapt<List<DynamicChartDto>>(), dto.TotalCount);
        }
    }

}